package self.rss.proto;



import self.rss.proto.util.ActivityRegistry;
import self.rss.proto.util.DatabaseManager;
import self.rss.proto.util.GetDisclaimer;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;


public class NewsShowSingle extends Activity {


	private SQLiteDatabase mDatenbank;
	private DatabaseManager newsHelper;
	private long _ID;
	private NewsShowSingle instance;
	private String link;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.einzelanzeige_news);
		ActivityRegistry.register(this);
		
		newsHelper = new DatabaseManager(this);
	}
	
	
	@Override
	protected void onResume() {
		super.onResume();
		
		if (getIntent().hasExtra("ID") == true) {
			_ID = getIntent().getExtras().getLong("ID");
		}
		
		mDatenbank = newsHelper.getReadableDatabase();
		ladeDaten();
		
	}
	
	@Override
    protected void onDestroy() {
        super.onDestroy();
        mDatenbank.close();
    }
	 
	
	public NewsShowSingle(){
		instance=this;
	}
	
	private void ladeDaten() {

		Cursor myCursor = mDatenbank.query(
				"titel",			// Tabellenname
				new String[] { 		// anzuzeigende Spalten
						"_id",
						"inhalt",
						"link",
						"titel"
				}, 
				"_id="+_ID, 		// WHERE (z.B. "_id = ?")
				null, 				// WHERE-Argumente (f�r "?")
				null, 				// GROUP BY
				null, 				// HAVING
				null				// ORDER BY
			);
		 startManagingCursor(myCursor);
		 myCursor.moveToFirst();
		
		 
	if (myCursor!=null){
		if(myCursor.isFirst()){
			

		TextView labelTitel = (TextView) findViewById(R.id.tx_titel);
		TextView labelInhalt = (TextView) findViewById(R.id.tx_inhalt);
	
		link = myCursor.getString(2);
		
			labelTitel.setText(Html.fromHtml(myCursor.getString(3)));
			labelInhalt.setText(Html.fromHtml(myCursor.getString(1)));
		}
		
	
	}
	
	}
	 public void onButtonClick(View v){
		 
		 Intent intent = null;
		 intent = new Intent(Intent.ACTION_VIEW,
			Uri.parse(link));
	startActivity(intent);
	}
	 
	  @Override
		public boolean onCreateOptionsMenu(Menu menu) {
			getMenuInflater().inflate(R.menu.menue, menu);
			
			return super.onCreateOptionsMenu(menu);
		}
	 
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
	

		case R.id.start_seite:
			startActivity(new Intent(this, NewsProgress.class));
			
			return true;
			
		case R.id.menue_hilfe:
			GetDisclaimer.disclaimer(instance,getString(R.string.infodisclaimer));
			return true;

		case R.id.opt_beenden:
			ActivityRegistry.finishAll();
		
			return true;
			
			
		}
		return super.onOptionsItemSelected(item);
	}
	 
}
	
	


